import cv2
import types

real = {
    'pic1': [
        (5, 45),
        (2.86, 25.71)
    ],
    'pic2': [
        (10, 79),
        (2.61, 23.34)
    ],
    'pic3': [
        (10, 50),
        (3.09, 15.46),
    ]
}

import numpy as np


def calculate_mae(y_true, y_pred):
    """
    计算平均绝对误差 (MAE)
    参数:
        y_true: 真实值数组
        y_pred: 预测值数组
    返回:
        float: MAE值
    """
    return np.mean(np.abs(y_true - y_pred))


def calculate_mse(y_true, y_pred):
    """
    计算均方误差 (MSE)
    参数:
        y_true: 真实值数组
        y_pred: 预测值数组
    返回:
        float: MSE值
    """
    return np.mean((y_true - y_pred) ** 2)


def calculate_rmse(y_true, y_pred):
    """
    计算均方根误差 (RMSE)
    参数:
        y_true: 真实值数组
        y_pred: 预测值数组
    返回:
        float: RMSE值
    """
    mse = calculate_mse(y_true, y_pred)
    return np.sqrt(mse)


def gap(pic_name, scale_bar: tuple, spacing: tuple):
    if pic_name in real:
        pic = real[pic_name]
        scale_bar_actual, scale_bar_pixels = pic[0]
        avg_pixel_spacing, actual_spacing = pic[1]
        predict_scale_bar_actual, predict_scale_bar_pixels = scale_bar
        predict_avg_pixel_spacing, predict_actual_spacing = spacing
